YUI().use('dd-constrain', 'dd-proxy', 'dd-drop' ,'io', function(Y) {
    //Listen for all drop:over events
    Y.DD.DDM.on('drop:over', function(e) {
        //Get a reference to our drag and drop nodes
        var drag = e.drag.get('node'),
            drop = e.drop.get('node');
        
        //Are we dropping on a li node?
        if (drop.get('tagName').toLowerCase() === 'div' && drop.hasClass('item-entry')) {
            //Are we not going up?
            if (!goingUp) {
                drop = drop.get('nextSibling');
            }
            //Add the node to this list
            e.drop.get('node').get('parentNode').insertBefore(drag, drop);
            //Resize this nodes shim, so we can drop on it later.
            e.drop.sizeShim();
        }
    });
	
	
    //Listen for all drag:drag events
    Y.DD.DDM.on('drag:drag', function(e) {
        //Get the last y point
        var y = e.target.lastXY[1];
        //is it greater than the lastY var?
        if (y < lastY) {
            //We are going up
            goingUp = true;
        } else {
            //We are going down.
            goingUp = false;
        }
        //Cache for next check
        lastY = y;
    });
    //Listen for all drag:start events
    Y.DD.DDM.on('drag:start', function(e) {
        //Get our drag object
        var drag = e.target;
        //Set some styles here
        drag.get('node').setStyle('opacity', '.25');
        drag.get('dragNode').set('innerHTML', drag.get('node').get('innerHTML'));
        drag.get('dragNode').setStyles({
            opacity: '.5',
            borderColor: drag.get('node').getStyle('borderColor'),
            backgroundColor: drag.get('node').getStyle('backgroundColor')
        });
    });
    //Listen for a drag:end events
    Y.DD.DDM.on('drag:end', function(e) {
        var drag = e.target;
        //alert('draged');
        //Put our styles back
        drag.get('node').setStyles({
            visibility: '',
            opacity: '1'
            
        });
		
		// remvove style of div.remove 
                Y.all('#category_third div.recyclebin').setStyles({
                    display:'block'
                });
                
		Y.all('#category_third div.drop-remove-container_third').setStyles({
                                opacity: '1',
				 zoom: '1',
				 '-moz-transform': 'scale(1)',
				 '-webkit-transform': 'scale(1)'
			});
    });
    //Listen for all drag:drophit events
    Y.DD.DDM.on('drag:drophit', function(e) {
        var drop = e.drop.get('node'),
            drag = e.drag.get('node');
         //alert('drag:drophit');
        //if we are not on an li, we must have been dropped on a ul
		
        if (drop.get('tagName').toLowerCase() === 'div' && drop.hasClass('item-entry')) {
            if (!drop.contains(drag)) {
                //  drop.appendChild(drag);
				//Add the node to this list
            e.drop.get('node').get('parentNode').insertBefore(drag, drop);
            //Resize this nodes shim, so we can drop on it later.
            //e.drop.sizeShim();
            }
        }
    });
    
    //Static Varss
    var goingUp = false, lastY = 0;

    //Get the list of li's in the lists and make them draggable
    var lis = Y.Node.all('#category_third div.item-entry-container-third div.item-entry');
    lis.each(function(v, k) {
        var dd = new Y.DD.Drag({
            node: v,
            target: {
                padding: '0 0 0 20'
            }
        }).plug(Y.Plugin.DDProxy, {
            moveOnEnd: false
        }).plug(Y.Plugin.DDConstrained, {
            constrain2node: '#category_third'
        });
    });

    //Create simple targets for the 2 lists.
	
	  var uls = Y.Node.all('#category_third div.item-entry-container-third div.item-entry');
		uls.each(function(v, k) {
			var tar = new Y.DD.Drop({
				node: v
			});
		});
		
		

		
		//=======================  remove drop container 
		var drop_remove = new Y.DD.Drop({
            node: '#category_third div.drop-remove-container_third'
        });
        drop_remove.on('drop:hit', function(e) {
		//alert('drop:hit:drop_remove');
		var drag = e.drag;
		
                //ajax call 
                var itemIdRemove = drag.get('node').one('input[name=itemId][type=hidden]').get('value');
                
                //alert('valueId='+itemIdRemove);
                
                var answer = confirm("You want to remove ? ");
                                if (answer){
                                    // ajax call 
                                        Y.io('index.php/item/deleteItem/'+itemIdRemove,
                                            {
                                                on: {success: function(){
                                                        //alert('success');
                                                        drag.get('node').remove();
                                                }}
                                            });
                                        //return true;
                                }
                // remove successfully and remove node DOM
		
		
           
        });
		 drop_remove.on('drop:enter', function(e) {
		//alert('drop:hit:drop_remove');
		//var drop = e.drop.get('node');
		
                 Y.all('#category_third div.recyclebin').setStyles({
                    display:'none'
                });
		this.get('node').setStyles({
				opacity: '1',
                                zoom: '1.1',
				 '-moz-transform': 'scale(1.8)',
				 '-webkit-transform': 'scale(1.8)'
                                 
			});
        });
		
		drop_remove.on('drop:exit', function(e) {
		//alert('drop:hit:drop_remove');
		//var drop = e.drop;
                 Y.all('#category_third div.recyclebin').setStyles({
                    display:'block'
                });
		this.get('node').setStyles({
				opacity: '1',
				 zoom: '1',
				 '-moz-transform': 'scale(1)',
				 '-webkit-transform': 'scale(1)'
			});
        });
});

// ==================  
   
    
    function prev_ItemEntries($_category_id){
        var   index_value = jQuery("#list-one input[name=item_index]").val();
        //alert('index_value '+ index_value);
        
         jQuery.ajax({
                type:'GET',
                url:'index.php/item/prev_ItemEntries/'+$_category_id+'/'+index_value,
                success:function(respone){
                    //alert(respone);
                    jQuery("div.item-entry-container-third").html(respone);
                }
            });
    }
    
    function next_ItemEntries ($_category_id){
        var   index_value = jQuery("#list-one input[name=item_index]").val();
        //alert('index_value '+ index_value);
         jQuery.ajax({
                type:'GET',
                url:'index.php/item/next_ItemEntries/'+$_category_id+'/'+index_value,
                success:function(respone){
                    //alert(respone);
                    jQuery("div.item-entry-container-third").html(respone);
                }
            });
    }


    function prev_ItemEntries2($_category_id, varDiv){
       // var   index_value = jQuery("#list-one input[name=item_index]").val();
       
var select =  varDiv+' input[name=item_index]';
        var   index_value = jQuery(select ).val();
 //alert("index_value "+index_value );
        
         jQuery.ajax({
                type:'GET',
                url:'index.php/item/prev_ItemEntries/'+$_category_id+'/'+index_value,
                success:function(respone){
                    //alert(respone);
                    jQuery(varDiv).html(respone);
                }
            });
    }
    
    function next_ItemEntries2 ($_category_id, varDiv){

	var select =  varDiv+' input[name=item_index]';
        var   index_value = jQuery(select ).val();
        //alert(varDiv);
         jQuery.ajax({
                type:'GET',
                url:'index.php/item/next_ItemEntries/'+$_category_id+'/'+index_value,
                success:function(respone){
                    //alert(respone);
                    jQuery(varDiv).html(respone);
                }
            });
    }

 


